home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / mawk10.zip / CODE.C < prev    next >
C/C++ Source or Header  |  1991-10-05  |  3KB  |  122 lines

  1.  
  2. /********************************************
  3. code.c
  4. copyright 1991, Michael D. Brennan
  5.  
  6. This is a source file for mawk, an implementation of
  7. the AWK programming language.
  8.  
  9. Mawk is distributed without warranty under the terms of
  10. the GNU General Public License, version 2, 1991.
  11. ********************************************/
  12.  
  13.  
  14. /* $Log:    code.c,v $
  15.  * Revision 3.4.1.1  91/09/14  17:22:52  brennan
  16.  * VERSION 1.0
  17.  * 
  18.  * Revision 3.4  91/08/13  06:50:59  brennan
  19.  * VERSION .9994
  20.  * 
  21.  * Revision 3.3  91/06/28  04:16:15  brennan
  22.  * VERSION 0.999
  23.  * 
  24.  * Revision 3.2  91/06/27  08:23:57  brennan
  25.  * bigger page size for main code 
  26.  * bigger loop stacks -- both changes need to handle AWF
  27.  * 
  28.  * Revision 3.1  91/06/07  10:27:03  brennan
  29.  * VERSION 0.995
  30.  * 
  31.  * Revision 2.1  91/04/08  08:22:46  brennan
  32.  * VERSION 0.97
  33.  * 
  34. */
  35.  
  36. /*  code.c  */
  37.  
  38. #include "mawk.h"
  39. #include "code.h"
  40. #include "init.h"
  41.  
  42.  
  43. #define   CODE_SZ      (PAGE_SZ*sizeof(INST))
  44. #define   MAIN_CODE_SZ  (MAIN_PAGE_SZ*sizeof(INST))
  45.  
  46. INST *code_ptr  ;
  47. INST *main_start , *main_code_ptr ;
  48. INST *begin_start , *begin_code_ptr ;
  49. INST *end_start , *end_code_ptr ;
  50. unsigned main_size , begin_size, end_size ;
  51.     /* when the code is done executing its freed,
  52.        that's why this is global */
  53.  
  54. void  PROTO(fdump, (void) ) ;
  55.  
  56. void  code_init()
  57.   code_ptr = main_code_ptr = main_start 
  58.     = (INST *) zmalloc(MAIN_CODE_SZ) ;
  59. #if 0
  60.   begin_code_ptr = begin_start = (INST *) zmalloc(CODE_SZ) ;
  61.   end_code_ptr = end_start = (INST *) zmalloc(CODE_SZ) ;
  62.   code_ptr = main_code_ptr ;
  63. #endif
  64. }
  65.  
  66. void code_cleanup()
  67.   if ( dump_code )  fdump() ; /* dumps all functions */
  68.  
  69.   if ( begin_start )
  70.   { 
  71.     begin_code_ptr++->op = _HALT ;
  72.     if ( (begin_size = begin_code_ptr - begin_start) > PAGE_SZ )
  73.     overflow("BEGIN code", PAGE_SZ) ;
  74.  
  75.     begin_size *= sizeof(INST) ;
  76.     begin_start = (INST *) zrealloc(begin_start, CODE_SZ , begin_size) ;
  77.  
  78.     if ( dump_code )
  79.     { fprintf(stderr, "BEGIN\n") ;
  80.       da(begin_start, stderr) ; 
  81.     }
  82.   }
  83.  
  84.   if ( end_start )
  85.   { 
  86.     end_code_ptr++->op = _HALT ;
  87.     if ( (end_size = end_code_ptr - end_start) > PAGE_SZ )
  88.     overflow("END code", PAGE_SZ) ;
  89.  
  90.     end_size *= sizeof(INST) ;
  91.     end_start = (INST *) zrealloc(end_start, CODE_SZ , end_size) ;
  92.  
  93.     if ( dump_code )
  94.     { fprintf(stderr, "END\n") ;
  95.       da(end_start, stderr) ; 
  96.     }
  97.   }
  98.  
  99.     /* main_start is always set */
  100.     code_ptr++->op = _HALT ;
  101.     if ( (main_size = code_ptr - main_start) == 1 ) /* empty */
  102.     {
  103.       zfree( main_start, MAIN_CODE_SZ ) ;
  104.       main_start = (INST *) 0 ;
  105.     }
  106.     else
  107.     if ( main_size > MAIN_PAGE_SZ ) overflow("MAIN code" , MAIN_PAGE_SZ) ;
  108.     else
  109.     {  
  110.        main_size *= sizeof(INST) ;
  111.        main_start = (INST *) zrealloc(main_start, MAIN_CODE_SZ, 
  112.             main_size ) ;
  113.  
  114.        if ( dump_code )
  115.        { fprintf(stderr, "MAIN\n") ;
  116.          da(main_start, stderr) ;
  117.        }
  118.     }
  119. }
  120.